﻿package com.sms.monitor.ui.activity;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.sms.monitor.R;
import com.sms.monitor.constant.Constant;
/**
 *	短信弹出框
 * 
 *
 */
public class DialogActivity extends Activity implements OnClickListener{
	private TextView	mContent;		
	private TextView	mPhone;			
	private Button		mClose;			
	private TextView	mLength;		
	private TextView	mReceiveTime;
	private Timer		mTimer;
	private static final int DELAY = 30*1000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// 
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog);
		findViews();
		init();
		
	}

	private void findViews() {
		mContent = (TextView) findViewById(R.id.tv_msg);
		mPhone = (TextView) findViewById(R.id.tv_phone);
		mClose = (Button) findViewById(R.id.btn_close);
		mLength = (TextView) findViewById(R.id.tv_msg_length);
		mReceiveTime = (TextView) findViewById(R.id.tv_receive_time);
	}
	private void init() {
		// 
		Bundle bundle = getIntent().getExtras();
		mReceiveTime.setText(bundle.getString(Constant.KEY_SMS_RECEIVE_TIME));
		mLength.setText(bundle.getString(Constant.KEY_SMS_LENGTH));
		mPhone.setText(bundle.getString(Constant.KEY_SMS_SEND_PHONE));
		mContent.setText( Html.fromHtml(bundle.getString(Constant.KEY_SMS_MSG)));
		//添加跳转链接
		mContent.setMovementMethod(LinkMovementMethod.getInstance());
		mClose.setOnClickListener(this);
		mTimer = new Timer();
		//30秒定时关闭对话框。
		mTimer.schedule(new TimerTask() {
			@Override
			public void run() {
				// 
				finish();
			}
		} ,DELAY);
	}

	
	/**
	 * 关闭按钮事件
	 */
	@Override
	public void onClick(View v) {
		// 
		switch (v.getId()) {
		case R.id.btn_close:
			finish();
			break;

		default:
			break;
		}
	}
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if(mTimer != null){
			mTimer.cancel();
		}
	}
}
